\doxysection{x\+Message\+Buffer\+Receive\+From\+ISR }
\hypertarget{group__x_message_buffer_receive_from_i_s_r}{}\label{group__x_message_buffer_receive_from_i_s_r}\index{xMessageBufferReceiveFromISR@{xMessageBufferReceiveFromISR}}
\doxylink{message__buffer_8h_source}{message\+\_\+buffer.\+h}


\begin{DoxyPre}
size\_t xMessageBufferReceiveFromISR( MessageBufferHandle\_t xMessageBuffer,                                      void *pvRxData,                                      size\_t xBufferLengthBytes,                                      BaseType\_t *pxHigherPriorityTaskWoken );
\end{DoxyPre}


An interrupt safe version of the API function that receives a discrete message from a message buffer. Messages can be of variable length and are copied out of the buffer.

{\itshape {\bfseries{NOTE}}}\+: Uniquely among Free\+RTOS objects, the stream buffer implementation (so also the message buffer implementation, as message buffers are built on top of stream buffers) assumes there is only one task or interrupt that will write to the buffer (the writer), and only one task or interrupt that will read from the buffer (the reader). It is safe for the writer and reader to be different tasks or interrupts, but, unlike other Free\+RTOS objects, it is not safe to have multiple different writers or multiple different readers. If there are to be multiple different writers then the application writer must place each call to a writing API function (such as x\+Message\+Buffer\+Send()) inside a critical section and set the send block time to 0. Likewise, if there are to be multiple different readers then the application writer must place each call to a reading API function (such as x\+Message\+Buffer\+Read()) inside a critical section and set the receive block time to 0.

Use x\+Message\+Buffer\+Receive() to read from a message buffer from a task. Use x\+Message\+Buffer\+Receive\+From\+ISR() to read from a message buffer from an interrupt service routine (ISR).


\begin{DoxyParams}{Parameters}
{\em x\+Message\+Buffer} & The handle of the message buffer from which a message is being received.\\
\hline
{\em pv\+Rx\+Data} & A pointer to the buffer into which the received message is to be copied.\\
\hline
{\em x\+Buffer\+Length\+Bytes} & The length of the buffer pointed to by the pv\+Rx\+Data parameter. This sets the maximum length of the message that can be received. If x\+Buffer\+Length\+Bytes is too small to hold the next message then the message will be left in the message buffer and 0 will be returned.\\
\hline
{\em px\+Higher\+Priority\+Task\+Woken} & It is possible that a message buffer will have a task blocked on it waiting for space to become available. Calling x\+Message\+Buffer\+Receive\+From\+ISR() can make space available, and so cause a task that is waiting for space to leave the Blocked state. If calling x\+Message\+Buffer\+Receive\+From\+ISR() causes a task to leave the Blocked state, and the unblocked task has a priority higher than the currently executing task (the task that was interrupted), then, internally, x\+Message\+Buffer\+Receive\+From\+ISR() will set \texorpdfstring{$\ast$}{*}px\+Higher\+Priority\+Task\+Woken to pd\+TRUE. If x\+Message\+Buffer\+Receive\+From\+ISR() sets this value to pd\+TRUE, then normally a context switch should be performed before the interrupt is exited. That will ensure the interrupt returns directly to the highest priority Ready state task. \texorpdfstring{$\ast$}{*}px\+Higher\+Priority\+Task\+Woken should be set to pd\+FALSE before it is passed into the function. See the code example below for an example.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The length, in bytes, of the message read from the message buffer, if any.
\end{DoxyReturn}
Example use\+: 
\begin{DoxyPre}
// A message buffer that has already been created.
MessageBuffer\_t xMessageBuffer;

void vAnInterruptServiceRoutine( void )
\{
uint8\_t ucRxData[ 20 ];
size\_t xReceivedBytes;
BaseType\_t xHigherPriorityTaskWoken = pdFALSE;  // Initialised to pdFALSE.

    // Receive the next message from the message buffer.
    xReceivedBytes = xMessageBufferReceiveFromISR( xMessageBuffer,
                                                  ( void * ) ucRxData,
                                                  sizeof( ucRxData ),
                                                  \&xHigherPriorityTaskWoken );

    if( xReceivedBytes > 0 )
    \{
        // A ucRxData contains a message that is xReceivedBytes long.  Process
        // the message here....
    \}

    // If xHigherPriorityTaskWoken was set to pdTRUE inside
    // xMessageBufferReceiveFromISR() then a task that has a priority above the
    // priority of the currently executing task was unblocked and a context
    // switch should be performed to ensure the ISR returns to the unblocked
    // task.  In most FreeRTOS ports this is done by simply passing
    // xHigherPriorityTaskWoken into portYIELD\_FROM\_ISR(), which will test the
    // variables value, and perform the context switch if necessary.  Check the
    // documentation for the port in use for port specific instructions.
    portYIELD\_FROM\_ISR( xHigherPriorityTaskWoken );
\}
\end{DoxyPre}
 